package com.cjm.one.goods.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import com.cjm.one.common.exception.GlobalException;
import com.cjm.one.common.result.ResultCodeEnum;
import com.cjm.one.goods.mapper.GoodBrandsMapper;
import com.cjm.one.goods.mapper.GoodsInfoMapper;
import com.cjm.one.goods.service.GoodBrandsService;
import com.cjm.one.model.goods.entity.GoodsBrand;
import com.cjm.one.model.goods.entity.GoodsInfo;
import com.cjm.one.model.goods.vo.GoodsBrandVo;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.ArrayList;

/**
* @author 29289
* @description 针对表【good_brand】的数据库操作Service实现
* @createDate 2024-09-05 16:06:59
*/
@Service
public class GoodBrandsServiceImpl extends ServiceImpl<GoodBrandsMapper, GoodsBrand>
    implements GoodBrandsService {
    @Resource
    private GoodBrandsMapper goodBrandMapper;

    @Resource
    private GoodsInfoMapper goodsInfoMapper;

    @Override
    public Page<GoodsBrandVo> pageList(Page<GoodsBrandVo> page, String name) {

      Page<GoodsBrandVo> pages = goodBrandMapper.selectPageList(page, name);
        return pages;
    }

    @Override
    public Boolean removeGoodBrandById(Long id) {
        LambdaQueryWrapper<GoodsInfo> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(GoodsInfo::getBrandId,id);
        Long count = goodsInfoMapper.selectCount(queryWrapper);
        if (count > 0) {
            throw new GlobalException(ResultCodeEnum.DELETE_GOODS_BRAND_ERROR);
        }
        int i = goodBrandMapper.deleteById(id);
        return i > 0;
    }

    @Override
    public ArrayList<GoodsBrandVo> selectGoodsBrandAll() {
        return goodBrandMapper.selectGoodsBrandAll();
    }
}




